package com.hualan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hualan.mapper.InformBulletinMapper;
import com.hualan.pojo.InformBulletin;
import com.hualan.pojo.PageResult;
import com.hualan.service.InformBulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformBulletinServiceImpl implements InformBulletinService {

    @Autowired
    private InformBulletinMapper informBulletinMapper;

    @Override
    public PageResult<InformBulletin> getPageList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<InformBulletin> list = informBulletinMapper.selectAll();
        Page<InformBulletin> p = (Page<InformBulletin>) list;
        return new PageResult<>(p.getTotal(), p.getResult());
    }

    @Override
    public InformBulletin getById(Integer id) {
        return informBulletinMapper.selectById(id);
    }

    @Override
    public int add(InformBulletin informBulletin) {
        return informBulletinMapper.insert(informBulletin);
    }

    @Override
    public int update(InformBulletin informBulletin) {
        return informBulletinMapper.update(informBulletin);
    }

    @Override
    public int delete(Integer id) {
        return informBulletinMapper.deleteById(id);
    }

    @Override
    public PageResult<InformBulletin> getPageListByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<InformBulletin> list = informBulletinMapper.selectByKeyword(keyword);
        Page<InformBulletin> p = (Page<InformBulletin>) list;
        return new PageResult<>(p.getTotal(), p.getResult());
    }
}